﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ElanReader
{
  public  class TrackLayer
    {
        //private List<Segment> _listOfTransciption;
        //private List<Segment> _listOfEnverment;
        //private List<Segment> _listOfSpeaker;
        //private List<Segment> _listOfStoryTopic;
        //private List<Segment> _listOfLanguagle;
        public int[,] Track;
        private int _maxt;
        private int _mxtlayer;
        public TrackLayer(int maxT,int maxlayer) {
            _maxt = maxT;
                _mxtlayer = maxlayer;
            Track = new int[maxT, maxlayer];
            for (int i = 0; i < maxT; i++)
            {
               
                for (int j = 0; j < maxlayer; j++)
                {
                    Track[i, j] = -1;
                }
            }
            
        }
        public void fillTrack(List<Segment> input, int index)
        {
            for (int i = 0; i < input.Count; i++)
            {
                Segment s = input[i];
                int t1 = s.itimestart / 1000;
                int t2 = s.itimeend / 1000;
                if (t1 < t2)
                {
                    for (int j = t1; j < t2; j++)
                    {
                        setValue(j, index, i);
                    }
                }
                else
                {
                    setValue(t1, index, i);
                }
            }

        }
        private void setValue(int timeIndex,int cindex,int thisValue)
        {
            if (timeIndex > _maxt) throw new Exception("Time index out of range");
            Track[timeIndex, cindex] = thisValue;
        }
        public int[] getTranckAtTimeSecond(int input)
        {
            if (input < _maxt)
            {
                int[] rv = new int[_mxtlayer];

                for (int i = 0; i < _mxtlayer; i++)
                {
                    rv[i] = Track[input, i];
                }
                return rv;
            }
            else
            {
                return null;
            }
        }
    }
}
